$(document).ready(function() {

	    // Templates
	    var linksTemplate = "{{#children}}<article class='linkWrap'><a class='link' href='{{data.url}}' data-id='{{data.id}}' target='_blank'><div class='linkInfo'><p class='linkTitle'>{{data.title}}</p><p class='linkDomain'>{{data.domain}}</p><p class='linkSub'>{{data.subreddit}}</p></div><div class='linkThumb'><div style='background-image: url({{data.thumbnail}})'></div></div></a><div class='toComments' data-id='{{data.id}}'><div></div></div></article>{{/children}}<div class='listButton'><span id='moreLinks'>More</span></div>",
	        linksTemplateLeft = "{{#children}}<article class='linkWrap'><a class='link' href='{{data.url}}' data-id='{{data.id}}' target='_blank'><div class='linkThumb'><div class='marginless' style='background-image: url({{data.thumbnail}})'></div></div><div class='linkInfo thumbLeft'><p class='linkTitle'>{{data.title}}</p><p class='linkDomain'>{{data.domain}}</p><p class='linkSub'>{{data.subreddit}}</p></div></a><div class='toComments' data-id='{{data.id}}'><div class='rightArrow'></div></div></article>{{/children}}<div class='listButton'><span id='moreLinks'>More</span></div>",
	        linkSummaryTemplate = "<section><div id='linkSummary'><a href='{{url}}' target='_blank'><p id='summaryTitle'>{{title}}</p><p id='summaryDomain'>{{domain}}</p></a><p id='summaryAuthor'>by {{author}}</p></div><div id='summaryExtra'><p id='summarySub'>{{subreddit}}</p><p id='summaryTime'></p><p id='summaryCommentNum'>{{num_comments}} comments</p></div></section>",
	        allSubredditsTemplate = "{{#children}}<div class='subreddit'><div><p class='subredditTitle'>{{data.display_name}}</p><p class='subredditDesc'>{{data.public_description}}</p></div><div class='btnAddSub'><div></div></div></div>{{/children}}",
	        botonAgregarSubManualTemplate = "<div id='topButtons'><div id='btnSubMan'>Insert Manually</div><div id='btnAddChannel'>Add Channel</div></div>",
	        formAgregarSubManualTemplate = '<div class="newForm" id="formNuevoSub"><div class="closeForm">close</div><form><input type="text" id="txtNuevoSub" placeholder="New subreddit name" /></form></div>',
	        formAddNewChannelTemplate = '<div class="newForm" id="formNewChannel"><div class="closeForm">close</div><input type="text" id="txtChannel" placeholder="Channel name" /><div id="subsForChannel"><input type="text" placeholder="Subreddit 1" /><input type="text" placeholder="Subreddit 2" /><input type="text" placeholder="Subreddit 3" /></div><div id="btnAddNewChannel">Add Channel</div></div>',
	        botonCargarMasSubsTemplate = "<div class='listButton'><span id='moreSubs'>More</span></div>",
	        savedSubredditsListToRemoveTemplate = "<ul class='removeList'>{{#.}}<div class='itemToRemove subToRemove'><p>{{.}}</p><div></div></div>{{/.}}</ul>",
	        savedChannelsListToRemoveTemplate = "<p id='removeTitle'>Channels</p><ul class='removeList'>{{#.}}<div class='itemToRemove channelToRemove'><p>{{name}}</p><div></div></div>{{/.}}</ul>",
	        channelTemplate = '<li><div class="channel"><p>{{name}}</p><div>{{#subs}}<p>{{.}}</p>{{/subs}}</div></div></li>',
	        channelsTemplate = '{{#.}}' + channelTemplate + '{{/.}}',
	        noLinkTemplate = "<div id='noLink'><p>No Post Selected.</div>",
	        aboutTemplate = "<div class='newForm aboutReeddit'><div class='closeForm'>close</div><ul><li><a href='./about' target='_blank'>Reeddit info site</a></li><li><a href='https://github.com/berbaquero/reeddit' target='_blank'>GitHub Project</a></li></ul><p>Built by <a href='https://twitter.com/berbaquero' target='_blank'>@BerBaquero</a></p></div>";

	    // Pseudo-Globals
	    var ancho = $(window).width(),
	        currentView = 1,
	        editingSubs = false,
	        urlInit = "http://www.reddit.com/",
	        urlEnd = ".json?jsonp=?",
	        urlLimitEnd = ".json?limit=30&jsonp=?",
	        loadedLinks = {},
	        posts = {},
	        replies = {},
	        current = {},
	        channels = [],
	        showingMenu = false,
	        subreddits, store = window.fluid ? allCookies : window.localStorage,
	        ultimoLink, ultimoSub, esModal = false,
	        loadingComments = false,
	        
	        // Pseudo-Enums
	        move = {
	            left: 1,
	            right: 2
	        },
	        view = {
	            main: 1,
	            comments: 2
	        },
	        selection = {
	            sub: 1,
	            channel: 2
	        },
	        transforms = {
	            translateTo0: 'translate3d(0px, 0px, 0px)',
	            translateTo140: 'translate3d(140px, 0px, 0px)'
	        };

	    var defaultSubs = ["frontPage", "pics", "funny", "IAmA", "AskReddit", "worldNews", "todayilearned", "technology", "science", "atheism", "geek", "videos", "reactiongifs", "AdviceAnimals", "aww"];

	    var defaultChannel = [{
	        name: 'Media',
	        subs: ["movies", "music", "games"],
	        url: 'r/movies+music+games'
	    }];

	    tappable("#breaking", {
	        onTap: function() {
	            $.ajax({
				  type: 'GET',
				  url: 'http://andhrajyothy.com/MainNews.asp',
				  // data to be added to query string:
				  data: {name:'qry=dailyupdates/main'},
				  // type of data we are expecting in return:
				  dataType: 'html',
				  header:'Access-Control-Request-Method: POST',
				  timeout: 100000,
				  context: $('body'),
				  success: function(data){
				    // Supposing this JSON payload was received:
				    //   {"project": {"id": 42, "html": "<div>..." }}
				    // append the HTML to context object.
				    alert(data);
				  },
				  error: function(xhr, type, error){
				    alert('Ajax error! '+ type);
				  }
				})
	        }
	    });
});